package com.ruoyi.report_sh.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_sh.domain.bo.ReportShShmdwxhczhlhslxdjlbBsInfoBo;
import com.ruoyi.report_sh.domain.vo.ReportShShmdwxhczhlhslxdjlbBsInfoVo;
import com.ruoyi.report_sh.domain.ReportShShmdwxhczhlhslxdjlbBsInfo;
import com.ruoyi.report_sh.mapper.ReportShShmdwxhczhlhslxdjlbBsInfoMapper;
import com.ruoyi.report_sh.service.IReportShShmdwxhczhlhslxdjlbBsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 石灰密度、未消化残渣含量、含水率、细度试验检测记录Service业务层处理
 *
 * @author llb
 * @date 2024-09-04
 */
@RequiredArgsConstructor
@Service
public class ReportShShmdwxhczhlhslxdjlbBsInfoServiceImpl implements IReportShShmdwxhczhlhslxdjlbBsInfoService {

    private final ReportShShmdwxhczhlhslxdjlbBsInfoMapper baseMapper;

    /**
     * 查询石灰密度、未消化残渣含量、含水率、细度试验检测记录
     */
    @Override
    @FIllBasicInfo
    public ReportShShmdwxhczhlhslxdjlbBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询石灰密度、未消化残渣含量、含水率、细度试验检测记录列表
     */
    @Override
    public TableDataInfo<ReportShShmdwxhczhlhslxdjlbBsInfoVo> queryPageList(ReportShShmdwxhczhlhslxdjlbBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportShShmdwxhczhlhslxdjlbBsInfo> lqw = buildQueryWrapper(bo);
        Page<ReportShShmdwxhczhlhslxdjlbBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询石灰密度、未消化残渣含量、含水率、细度试验检测记录列表
     */
    @Override
    public List<ReportShShmdwxhczhlhslxdjlbBsInfoVo> queryList(ReportShShmdwxhczhlhslxdjlbBsInfoBo bo) {
        LambdaQueryWrapper<ReportShShmdwxhczhlhslxdjlbBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportShShmdwxhczhlhslxdjlbBsInfo> buildQueryWrapper(ReportShShmdwxhczhlhslxdjlbBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportShShmdwxhczhlhslxdjlbBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getTotalPage() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(bo.getPage() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getPage, bo.getPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), ReportShShmdwxhczhlhslxdjlbBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), ReportShShmdwxhczhlhslxdjlbBsInfo::getJilbh, bo.getJilbh());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), ReportShShmdwxhczhlhslxdjlbBsInfo::getGongcmc, bo.getGongcmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), ReportShShmdwxhczhlhslxdjlbBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), ReportShShmdwxhczhlhslxdjlbBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), ReportShShmdwxhczhlhslxdjlbBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), ReportShShmdwxhczhlhslxdjlbBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), ReportShShmdwxhczhlhslxdjlbBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsj()), ReportShShmdwxhczhlhslxdjlbBsInfo::getYangpsj, bo.getYangpsj());
        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), ReportShShmdwxhczhlhslxdjlbBsInfo::getShiyjcrq, bo.getShiyjcrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), ReportShShmdwxhczhlhslxdjlbBsInfo::getShiytjwd, bo.getShiytjwd());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), ReportShShmdwxhczhlhslxdjlbBsInfo::getShiytjsd, bo.getShiytjsd());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), ReportShShmdwxhczhlhslxdjlbBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), ReportShShmdwxhczhlhslxdjlbBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), ReportShShmdwxhczhlhslxdjlbBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
        lqw.eq(bo.getHezl1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getHezl1, bo.getHezl1());
        lqw.eq(bo.getHezl2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getHezl2, bo.getHezl2());
        lqw.eq(bo.getHesyzl1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getHesyzl1, bo.getHesyzl1());
        lqw.eq(bo.getHesyzl2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getHesyzl2, bo.getHesyzl2());
        lqw.eq(bo.getHegyzl1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getHegyzl1, bo.getHegyzl1());
        lqw.eq(bo.getHegyzl2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getHegyzl2, bo.getHegyzl2());
        lqw.eq(bo.getShuifzl1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShuifzl1, bo.getShuifzl1());
        lqw.eq(bo.getShuifzl2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShuifzl2, bo.getShuifzl2());
        lqw.eq(bo.getGansyzl1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getGansyzl1, bo.getGansyzl1());
        lqw.eq(bo.getGansyzl2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getGansyzl2, bo.getGansyzl2());
        lqw.eq(bo.getHansldz1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getHansldz1, bo.getHansldz1());
        lqw.eq(bo.getHansldz2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getHansldz2, bo.getHansldz2());
        lqw.eq(bo.getHanslpjz() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getHanslpjz, bo.getHanslpjz());
        lqw.eq(bo.getShiywd1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShiywd1, bo.getShiywd1());
        lqw.eq(bo.getShiywd2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShiywd2, bo.getShiywd2());
        lqw.eq(bo.getShuidmd1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShuidmd1, bo.getShuidmd1());
        lqw.eq(bo.getShuidmd2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShuidmd2, bo.getShuidmd2());
        lqw.eq(bo.getShiyq1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShiyq1, bo.getShiyq1());
        lqw.eq(bo.getShiyq2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShiyq2, bo.getShiyq2());
        lqw.eq(bo.getShiyh1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShiyh1, bo.getShiyh1());
        lqw.eq(bo.getShiyh2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShiyh2, bo.getShiyh2());
        lqw.eq(bo.getJiashq1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getJiashq1, bo.getJiashq1());
        lqw.eq(bo.getJiashq2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getJiashq2, bo.getJiashq2());
        lqw.eq(bo.getJiashh1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getJiashh1, bo.getJiashh1());
        lqw.eq(bo.getJiashh2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getJiashh2, bo.getJiashh2());
        lqw.eq(bo.getShihmddz1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShihmddz1, bo.getShihmddz1());
        lqw.eq(bo.getShihmddz2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShihmddz2, bo.getShihmddz2());
        lqw.eq(bo.getShihmdpjz1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShihmdpjz1, bo.getShihmdpjz1());
        lqw.eq(bo.getShihmdpjz2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShihmdpjz2, bo.getShihmdpjz2());
        lqw.eq(bo.getShihxdmd() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShihxdmd, bo.getShihxdmd());
        lqw.eq(bo.getYangpzl1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getYangpzl1, bo.getYangpzl1());
        lqw.eq(bo.getYangpzl2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getYangpzl2, bo.getYangpzl2());
        lqw.eq(bo.getYangpzl3() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getYangpzl3, bo.getYangpzl3());
        lqw.eq(bo.getM11() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getM11, bo.getM11());
        lqw.eq(bo.getM12() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getM12, bo.getM12());
        lqw.eq(bo.getM13() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getM13, bo.getM13());
        lqw.eq(bo.getM21() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getM21, bo.getM21());
        lqw.eq(bo.getM22() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getM22, bo.getM22());
        lqw.eq(bo.getM23() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getM23, bo.getM23());
        lqw.eq(bo.getX11() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getX11, bo.getX11());
        lqw.eq(bo.getX12() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getX12, bo.getX12());
        lqw.eq(bo.getX13() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getX13, bo.getX13());
        lqw.eq(bo.getX21() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getX21, bo.getX21());
        lqw.eq(bo.getX22() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getX22, bo.getX22());
        lqw.eq(bo.getX23() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getX23, bo.getX23());
        lqw.eq(bo.getShiygzl1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShiygzl1, bo.getShiygzl1());
        lqw.eq(bo.getShiygzl2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShiygzl2, bo.getShiygzl2());
        lqw.eq(bo.getShiygzl3() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getShiygzl3, bo.getShiygzl3());
        lqw.eq(bo.getGanzl1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getGanzl1, bo.getGanzl1());
        lqw.eq(bo.getGanzl2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getGanzl2, bo.getGanzl2());
        lqw.eq(bo.getGanzl3() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getGanzl3, bo.getGanzl3());
        lqw.eq(bo.getBaifb1() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getBaifb1, bo.getBaifb1());
        lqw.eq(bo.getBaifb2() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getBaifb2, bo.getBaifb2());
        lqw.eq(bo.getBaifb3() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getBaifb3, bo.getBaifb3());
        lqw.eq(bo.getWeixjklhl() != null, ReportShShmdwxhczhlhslxdjlbBsInfo::getWeixjklhl, bo.getWeixjklhl());
        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), ReportShShmdwxhczhlhslxdjlbBsInfo::getFujsm, bo.getFujsm());
        lqw.eq(StringUtils.isNotBlank(bo.getJianc()), ReportShShmdwxhczhlhslxdjlbBsInfo::getJianc, bo.getJianc());
        lqw.eq(StringUtils.isNotBlank(bo.getJil()), ReportShShmdwxhczhlhslxdjlbBsInfo::getJil, bo.getJil());
        lqw.eq(StringUtils.isNotBlank(bo.getFuh()), ReportShShmdwxhczhlhslxdjlbBsInfo::getFuh, bo.getFuh());
        lqw.eq(StringUtils.isNotBlank(bo.getRiq()), ReportShShmdwxhczhlhslxdjlbBsInfo::getRiq, bo.getRiq());
        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), ReportShShmdwxhczhlhslxdjlbBsInfo::getShebIds, bo.getShebIds());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyjIds()), ReportShShmdwxhczhlhslxdjlbBsInfo::getPandyjIds, bo.getPandyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyjIds()), ReportShShmdwxhczhlhslxdjlbBsInfo::getJiancyjIds, bo.getJiancyjIds());
        return lqw;
    }

    /**
     * 新增石灰密度、未消化残渣含量、含水率、细度试验检测记录
     */
    @Override
    @DSTransactional
    public Boolean insertByBo(ReportShShmdwxhczhlhslxdjlbBsInfoBo bo) {
        ReportShShmdwxhczhlhslxdjlbBsInfo add = BeanUtil.toBean(bo, ReportShShmdwxhczhlhslxdjlbBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改石灰密度、未消化残渣含量、含水率、细度试验检测记录
     */
    @Override
    @DSTransactional
    public Boolean updateByBo(ReportShShmdwxhczhlhslxdjlbBsInfoBo bo) {
        ReportShShmdwxhczhlhslxdjlbBsInfo update = BeanUtil.toBean(bo, ReportShShmdwxhczhlhslxdjlbBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportShShmdwxhczhlhslxdjlbBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除石灰密度、未消化残渣含量、含水率、细度试验检测记录
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
